package com.zy.web.demo.wenjian;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/7/10 14:13
 */
public class wenjian {

    public static void main(String[] args) throws IOException {

//        File file = new File("E:\\编程\\项目\\text.txt");
//
//        BufferedWriter bs = new BufferedWriter(new FileWriter(file,true));
//
//        bs.write(String.valueOf(2));
//        bs.flush();
//        bs.close();
        wenjian wenjian = new wenjian();
        wenjian.file1();
    }

    public void file(){
        try {
            FileInputStream file = new FileInputStream(new File("C:\\Users\\wjy\\Desktop\\zy.txt"));
            byte[] bytes = new byte[1024];
            int len = 0;
            FileOutputStream os = new FileOutputStream(new File("C:\\Users\\wjy\\Desktop\\gg.txt"),true);
            while ( (len = file.read(bytes) ) != -1){
                os.write(bytes,0,len);
            }
            file.close();
            os.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void file1(){

        try {
            FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\wjy\\Desktop\\zy.txt"));
            byte[] bytes = new byte[1024];
            int len = 0;
            List<String> list = new ArrayList<>();
            while ( ( len =  inputStream.read(bytes)) != -1 ){
                list.add( new String(bytes) );
            }
            inputStream.close();
            for (String s : list) {
                System.out.println(s);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

    }



}
